package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mapper.CmsSubjectMapper;
import com.itheima.pojo.CmsSubject;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class CmsSubjectImpl implements CmsSubjectApi{

    @Autowired
    private CmsSubjectMapper mapper;

    /**
     * 获取全部商品专题
     */
    @Override
    public List<CmsSubject> listAll() {
        LambdaQueryWrapper<CmsSubject> lqw = new LambdaQueryWrapper<>();
        lqw.ne(CmsSubject::getId,0);
        List<CmsSubject> cmsSubjects = mapper.selectList(lqw);
        return cmsSubjects;
    }

    /**
     * 根据专题名称分页获取商品专题
     */
    @Override
    public IPage<CmsSubject> list(Integer pageNum, Integer pageSize, String keyword) {
        IPage<CmsSubject> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<CmsSubject> lqw = new LambdaQueryWrapper<>();
        lqw.like(ObjectUtils.isNotEmpty(keyword),CmsSubject::getCategoryName,keyword);
        mapper.selectPage(page,lqw);
        return page;
    }
}
